#include <stdio.h>
#include <sys/shm.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include "../../public/_public.h"

void memory_dump(void *ptr, int len)
{
    int i;

    for (i = 0; i < len; i++)
    {
        if (i % 8 == 0 && i != 0)
            printf(" ");
        if (i % 16 == 0 && i != 0)
            printf("\n");
        printf("%02x ", *((uint8_t *)ptr + i));
    }
    printf("\n");
}

CPActive active;

void handle(int sig)
{
    st_procinfo *shemptr = nullptr;
        int m_shmid=0;
        if ((m_shmid = shmget((key_t)SHMKEYP, MAXNUMP * sizeof(struct st_procinfo), 0666 | IPC_CREAT)) == -1)
        {
                printf("创建/获取共享内存(%x)失败。\n", SHMKEYP);
                return;
        }
        shemptr = (st_procinfo *)shmat(m_shmid, 0, 0);
        for(int i=0;i<3;i++)
        {
            printf("共享内存第%d位置的PID是%d\n",i,(shemptr+i)->pid);
        }
}

int main()
{
    signal(2,handle);

    // bool CPActive::AddPInfo(const int timeout,const char *pname,CLogFile *logfile)
    if (active.AddPInfo(3, "wanyingxing") == false)
    {
        printf("心眺信息加入失败\n");
        return -1;
    }
    // 写逻辑
    while (true)
    {
        active.UptATime();
        // 连接到贡献内存

    }
    return 0;
}
